﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Entity;
using BaiTu.DAL.EF;
using System.Data.Entity.Infrastructure;
using BaiTu.IDAL;

namespace BaiTu.Data.Testing
{
    [TestClass]
    public class UnitTest1
    {
        protected IDBContext _context;
        private IDataProvider _dataProvider;
        private IRepository<Domains.UserEntity> _repository;
        public UnitTest1() { }
        public UnitTest1(IDBContext context, IDataProvider dataProvider, IRepository<Domains.UserEntity> repository)
        {
            this._context = context;
            _dataProvider = dataProvider;
            _repository = repository;
        }

        [TestMethod]
        public void CreateDataBase()
        {
            var result = _repository.Add(new Domains.UserEntity()
                  {
                      Age = 21,
                      CreateTime = DateTime.Now,
                      Name = "郭志奇"
                  });
            if (result.Success == true)
            {
                Assert.AreEqual(1, 1);
            }
            Assert.AreEqual(1, 0);
        }


        [TestMethod]
        public void TestMethod1()
        {
        }

        [TestMethod]
        public void SchemaTest()
        {
            Database.SetInitializer<BaiTuContext>(null);
            var ctx = new BaiTuContext("Test");
            string result = ctx.CreateDatabaseScript();
            Console.WriteLine(result);
        }
        [TestMethod]
        public void Setup()
        {

        }

        protected string GetTestDbName()
        {
            string testDbName = "server=.;initial catalog=testbaitu;uid=sa;pwd=yuanjinzhou";
            return testDbName;

        }

        [TestMethod]
        public void Test()
        {

        }

        //public T SaveAndLoadEntity<T>(T entity, bool disposeContext = true) where T : Domains.BaseDomain
        //{
        //    context.Set<T>().Add(entity);
        //    context.SaveChanges();

        //    string id = entity.ID;
        //    if (disposeContext)
        //    {
        //        context.Dispose();
        //        context = new BaiTuContext(GetTestDbName());
        //    }
        //    var fromdb = context.Set<T>().Find(id);
        //    return fromdb;
        //}
    }
}
